package thread;
//法三：继承 Thread, 重写 run, 使用匿名内部类
public class Demo3 {
    public static void main(String[] args) throws InterruptedException {
        //临时定义一个 Thread 的子类，同时创建它的实例，省去了单独写子类的不走
        Thread t = new Thread() {
            //子类中的属性和方法

            @Override
            public void run() {
                while(true) {
                    System.out.println("hello thread");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };

        t.start();

        while(true) {
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
